<template>
  <transition name="slide">
    <music-list :title="title" :bgImage="bgImage" :songs="songs"></music-list>
  </transition>
</template>

<script>
import MusicList from '@/components/common/MusicList'

import { mapState } from 'vuex'
export default {
  data () {
    return {
      songs: [] // 歌曲列表
    }
  },
  components: {
    MusicList
  },
  methods: {
    checkRankId () {
      // 刷新返回前一页面
      if (!this.rank.topId) {
        this.$router.back()
      }
    },
    async getRankSongs () {
      this.songs = []
      const { data: res } = await this.$http.get('/api/top?id=' + this.rank.topId)
      this.songs = res.data.list
      // console.log(this.songs)
      // 成功
      // if (res.result === 100) {
      //   this.songs = res.data.list
      // } else {
      //   console.log('获取失败')
      // }
    }
  },
  computed: {
    ...mapState(['rank']),
    title () {
      return this.rank.label
    },
    bgImage () {
      return this.rank.picUrl
    }
  },
  watch: {
    rank () {
      this.getRankSongs()
    }
  },
  mounted () {
    // console.log(this.singer)
    this.checkRankId()
    this.getRankSongs()
  }
}
</script>

<style lang="stylus" scoped>
.slide-enter, .slide-leave-to {
  transform: translateX(100%);
}
.slide-enter-active, .slide-leave-active {
  transition: all .3s;
}
</style>
